<?php
namespace app\admins\controller;
/**
 * passport 登录授权管理
 */
class Passport extends Base{
        
    /**
     * 登录管理
     */
    public function login(){
        $Passport = \logic\user\Passport::getInstance();
        try{
            if($_POST){
                if(!captcha_check(input("code"))) E("图片校验码错误");                                
                $param = array(
                    'account'   => input("account"),
                    'password'  => input("password")
                );
                $userid = $Passport->login($param);
                $this->success('登录成功', '/Index/index');
            }
        }catch(\think\Exception $e){
            $this->error( $e->getMessage());
        }
        $User = $Passport->checkLogin($this->role);
        if( $User ) $this->redirect('/Index/index');
        $this->assign(get_defined_vars());
        return $this->fetch();        
    }
    
	/**
     * 退出登录
     */
    public function loginout(){        
        $Passport = \logic\user\Passport::getInstance();
        $Passport->unLogin();
        $this->success('成功退出系统', '/Passport/login');
    }
    
}
